home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / cl_clk10.zip / CLOCK.PRG < prev    next >
Text File  |  1993-03-24  |  15KB  |  369 lines

  1. /******************************************
  2. *  Function:    Clock
  3. *  Purpose:     Provides an on-screen clock
  4. *               (Screen Saver)
  5. *  Parameters:  hourmode12  :=  .T. for 12 Hour Am/Pm mode (default)
  6. *                               .F. for 24 Military time
  7. *               dispstring  :=  Character string to display under clock
  8. *                               (default is "Press Any Key to Continue...")
  9. *  Returns:     NIL
  10. *  Author:      Donald T. Olsen (c) copyright 1993
  11. *               96 OSS/OSOAC
  12. *               Dyess AFB, TX 79607
  13. *               Phone: (915)-696-2588 .or. AV: 461-2588
  14. *               Internet:
  15. *                    96wglglmpc@strathost.stratcom.af.mil
  16. *                    dolsen@dylan.af.mil
  17. *                    dolsen@donatello.af.mil
  18. *  Date:        24 March 1993
  19. *  Clipper:     Ver 5.01a
  20. *  Compile:     RTLINK clock /l /m /n
  21. *  Cost:        Free (of course), I only ask that you not sell it for
  22. *               your own profit.  If you change/enhance/rewrite it, do
  23. *               not redistribute your version.  Give me credit for the
  24. *               effort put into it.  (Integrity)
  25. *  Notes:       Additional notes can be found at the end of this program
  26. *               (That is my workspace.)
  27. *
  28. */
  29.  
  30. #include "SET.CH"
  31. #include "SETCURS.CH"
  32.  
  33. //                 Characters           Array Pos:       Used In Numbers:
  34. STATIC    char  :=  { " ─┐  ", ;     //     1            1
  35.                       "  │  ", ;     //     2            1
  36.                       "══╧══", ;     //     3            1
  37.                       "╓───┐", ;     //     4            2,3,5,6,7,8,9,0
  38.                       "    │", ;     //     5            2,3,4,5,7,9
  39.                       "╔═══╛", ;     //     6            2
  40.                       "║    ", ;     //     7            2,5,6
  41.                       "╚═══╛", ;     //     8            2,3,5,6,8,9,0
  42.                       "  ══╡", ;     //     9            3
  43.                       "║   │", ;     //    10            4,6,8,9,0
  44.                       "╚═══╡", ;     //    11            4,9
  45.                       "╚═══╕", ;     //    12            5
  46.                       "╠═══╡", ;     //    13            8
  47.                       "╠═══╕", ;     //    14            6
  48.                       "    ╛", ;     //    15            4,7
  49.                       "╓   ┐", ;     //    16            4
  50.                       "     "  }     //    17            Blank (12-Hour mode)
  51.  
  52. // cross-reference of chars array to construct the #s           Array Pos
  53. STATIC    ref  :=  { { 17, 17, 17, 17, 17 }, ;     //  Blank        1
  54.                      {  4, 10, 10, 10,  8 }, ;     //  Zero         2
  55.                      {  1,  2,  2,  2,  3 }, ;     //  One          3
  56.                      {  4,  5,  6,  7,  8 }, ;     //  Two          4
  57.                      {  4,  5,  9,  5,  8 }, ;     //  Three        5
  58.                      { 16, 10, 11,  5, 15 }, ;     //  Four         6
  59.                      {  4,  7, 12,  5,  8 }, ;     //  Five         7
  60.                      {  4,  7, 14, 10,  8 }, ;     //  Six          8
  61.                      {  4,  5,  5,  5, 15 }, ;     //  Seven        9
  62.                      {  4, 10, 13, 10,  8 }, ;     //  Eight       10
  63.                      {  4, 10, 11,  5,  8 }  }     //  Nine        11
  64. // and the others
  65. STATIC  clktop := 9, clkleft := 1, clkdir := 1
  66.  
  67. // clktop   := Starting row postion of clock when first called
  68. // clkleft  := Starting column position (1 while clock moves up)
  69. //                                     (32 while clock moves down)
  70. // clkdir   := Starting direction of clock movement 1=Up, -1=Down
  71.  
  72. FUNCTION Clock( hourmode12, dispstring )
  73. LOCAL inscreen, inrow, incol, incursor, incolor, inscore, nhour, moved, ;
  74.       am, ht, ho, mt, mo, st, so, line, outtahere, ddate
  75. inscreen   := SAVESCREEN( 0, 0, MAXROW(), MAXCOL() )
  76. inrow      := ROW()
  77. incol      := COL()
  78. incursor   := SETCURSOR( SC_NONE )
  79. incolor    := SETCOLOR("BG+/N")
  80. inscore    := SET(_SET_SCOREBOARD, .F.)
  81. moved      := .F.
  82. outtahere  := .F.
  83. hourmode12 := IF(hourmode12 = NIL, .T., hourmode12)
  84. dispstring := IF(dispstring = NIL, "Press Any Key to Continue...", dispstring)
  85. IF VALTYPE(hourmode12) + VALTYPE(dispstring) != "LC"
  86.   _Err_Msg("Programmer Error - Invalid Parameter type passed to Clock")
  87.   RETURN( NIL )
  88. ENDIF
  89.  
  90. // TIME() is in format "HH:MM:SS"  or  "12:56:23"
  91.  
  92. // Clear the screen and Display the unchangables (dots and dispstring)
  93. DispUnchangables( dispstring )
  94.  
  95. // Loop till a key is pressed, I'm outtahere.
  96. WHILE !outtahere
  97.   ddate := DATE()
  98.   DispDate( ddate )
  99.  
  100.   // Loop till the date changes
  101.   WHILE ddate = DATE() .and. !outtahere
  102.     am  := ( VAL(SUBSTR(TIME(), 1, 2) ) < 12 )
  103.     IF hourmode12
  104.       DispAmPm( am )
  105.     ENDIF
  106.  
  107.     // Loop till the Am/Pm changes
  108.     WHILE am = ( VAL(SUBSTR(TIME(), 1, 2) ) < 12 ) .and. !outtahere
  109.       nhour := VAL(SUBSTR(TIME(), 1, 2))
  110.       // nhour will be a string after the IF statement
  111.       IF hourmode12
  112.         // In 12 hour mode must subtract 12 from any time 1 pm and after
  113.         // Also Midnight to one o'clock is a 12 not a 0
  114.         nhour := PADL( ALLTRIM( STR( IF(nhour>12, nhour-12, IF(nhour = 0, 12, nhour)), 2 )), 2, "0")
  115.         ht  := IF( SUBSTR(nhour, 1, 1) = "0", 1, ;
  116.               VAL( SUBSTR(nhour, 1, 1) ) + 2 )
  117.       ELSE
  118.         nhour := PADL( ALLTRIM( STR( nhour, 2 ) ), 2, "0")
  119.         ht  := VAL( SUBSTR(nhour, 1, 1) ) + 2
  120.       ENDIF
  121.       ho    := VAL( SUBSTR(nhour, 2, 1) ) + 2
  122.       // 0 in the Update_um function is translated into the screen column
  123.       // at which the hours, minutes and seconds will be displayed
  124.       Update_um( 0, ht, ho )
  125.  
  126.       // Loop till the hour changes
  127.       WHILE ( nhour = SUBSTR(TIME(), 1, 2) .or. ;
  128.              IF(VAL(nhour)<12,VAL(nhour)+12,VAL(nhour)-12) = ;
  129.              VAL(SUBSTR(TIME(), 1, 2)) ) ;
  130.              .and. !outtahere
  131.  
  132.         mt    := VAL( SUBSTR(TIME(), 4, 1) ) + 2
  133.         mo      := VAL( SUBSTR(TIME(), 5, 1) ) + 2
  134.         Update_um( 1, mt, mo )
  135.  
  136.         // Loop till the minute changes
  137.         WHILE ALLTRIM(STR(mt-2,1))+ALLTRIM(STR(mo-2,1)) = ;
  138.               SUBSTR(TIME(), 4, 2) .and. !outtahere
  139.           st    := VAL( SUBSTR(TIME(), 7, 1) ) + 2
  140.           so    := VAL( SUBSTR(TIME(), 8, 1) ) + 2
  141.           // IF seconds/ones reaches 0 move clock
  142.           IF so - 2 = 0 .and. !moved
  143.             MoveClock()
  144.             // Moved indicates whether the clock has been moved during
  145.             // this 10 second cycle.  Without this flag the clock might
  146.             // move multiple times while the seconds are being updated
  147.             // with 0 in the ones position.  This way it will only move once.
  148.             moved := .T.
  149.             // If clock is at the top or bottom of the screen, flip sides
  150.             IF clktop = -1 .or. clktop = MAXROW() - 6
  151.               Flip_um()
  152.               // Redisplay the date and AmPm (if in that mode)
  153.               Dispdate(ddate)
  154.               IF hourmode12
  155.                 DispAmPm(am)
  156.               ENDIF
  157.             ENDIF
  158.           ENDIF
  159.           // If seconds/ones is 5 set moved off
  160.           IF so - 2 = 5
  161.             moved := .F.
  162.           ENDIF
  163.           Update_um( 2, st, so )
  164.           outtahere := ( INKEY() <> 0 )
  165.         ENDDO
  166.       ENDDO
  167.     ENDDO
  168.   ENDDO
  169. ENDDO
  170. // Reset the environment, you may need other resets
  171. RESTSCREEN( 0, 0, MAXROW(), MAXCOL(), inscreen )
  172. SETPOS( inrow, incol )
  173. SETCURSOR( incursor )
  174. SETCOLOR( incolor )
  175. SET(_SET_SCOREBOARD, inscore)
  176. RETURN( NIL )
  177.  
  178.  
  179. /******************************************
  180. *  Function:    Update_um
  181. *  Purpose:     Update any one of the Hour,
  182. *               Minute or Seconds Display
  183. *  Parameters:  Which ( a 0 for hours )
  184. *                     ( a 1 for minutes )
  185. *                     ( a 2 for seconds )
  186. *               Tens/Ones - array ref of
  187. *                  which number to display
  188. *  Called:      Anytime there is a change to
  189. *               the Hours, Minutes or Seconds
  190. */
  191. STATIC FUNCTION Update_um( which, tens, ones )
  192. LOCAL line, leftpos
  193. // Starting postions of numbers are 14 columns apart so...
  194. leftpos := clkleft+(which*14)
  195. FOR lin